import Vue from 'vue'
import axios from 'axios'
import { Message  } from 'element-ui'

axios.defaults.baseURL = 'http://localhost:8083/api'
// axios.defaults.baseURL = 'http:///3r56gy.natappfree.cc/api'
// interceptors request
axios.interceptors.request.use(config => {
  if (typeof document === 'object') {
    var token = document.cookie.split(";")[0].split("=")[1];  
    if (token) {
      config.headers.Authorization = token
    }
  }
  return config;
}, err => {
  return Promise.reject(err);
});

axios.interceptors.response.use(response => {
  if (response.data && response.data.code && response.data.code === -1) {
    Message.error(response.data.msg)
  }
  return response.data;
}, function (error) {
  return Promise.reject(error);
  });
Vue.prototype.$http = axios